#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
#include "regExp.h"
void Java_do1_mobo_jni_MoboJni_transFormRgba(JNIEnv * env, jobject obj,jbyteArray jSrcImgData,jintArray jDesImgData,jint width,jint height)
{
	int size,totalSize,i,j;
	unsigned char *data,*dataTemp;
	jint *jDesData;
	jbyte *jSrcData;
	jDesData = (*env)->GetIntArrayElements(env,jDesImgData,0);
	jSrcData=(*env)->GetByteArrayElements(env,jSrcImgData,0);
	if(!jDesImgData || !jSrcImgData)
	{
		return;
	}
	data=(unsigned char*)jDesData;
	dataTemp=(unsigned char*)jSrcData;
	size=width*4;
	totalSize=size*(height-1);
	dataTemp+=totalSize;
	for(i=0;i<height;i++)
	{
		memcpy(data,dataTemp,width*4);
		dataTemp-=size;
		data+=size;
	}
	
	(*env)-> ReleaseByteArrayElements(env, jSrcImgData, jSrcData, 0);
	(*env)-> ReleaseIntArrayElements(env, jDesImgData, jDesData, 0);
}

jlong Java_do1_mobo_jni_MoboJni_hashnr(JNIEnv * env, jobject obj,jstring fileName)
{
	unsigned int nr;
	unsigned int nr2;
	unsigned int nLen;
	char szName[260] = {0};
	char *ptName;
	char * jstr = (char *) (*env)->GetStringUTFChars(env, fileName, 0);
	if(!jstr)
	{
		return -1;
	}
	
	nr=1;
	nr2=4;
	ptName=szName;
	strcpy( szName,jstr );
	nLen = strlen( szName );
	while ( nLen-- )
	{
		nr ^= (((nr&63)+nr2)*((unsigned int)(unsigned char)*ptName++))+(nr<<8);
		nr2 += 3;
	}
	
	(*env)-> ReleaseStringUTFChars(env,fileName,jstr);
	
	return ((jlong)nr);
}


jboolean Java_do1_mobo_jni_MoboJni_Match(JNIEnv * env, jobject obj,jstring aText,jstring aRegExp)
{
	char *aTextCString;
	char *aRegExpCString; 
	jboolean result;
	result=0;
	aTextCString=(char *) (*env)->GetStringUTFChars(env, aText, 0);
	aRegExpCString=(char *) (*env)->GetStringUTFChars(env, aRegExp, 0);
	result=MoboMatch(aTextCString,aRegExpCString);
	(*env)-> ReleaseStringUTFChars(env,aText,aTextCString);
	(*env)-> ReleaseStringUTFChars(env,aRegExp,aRegExpCString);
	return result;
}